package Collection;

import lombok.Data;
import lombok.Getter;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author zhang
 */
public class Test {
    public static void main(String[] args) {
        Student student = new Student();
        Student student2 = new Student();
        System.out.println(student2.equals(student));

        System.out.println(student.hashCode());
        System.out.println(student2.hashCode());

        Set<Student> students = new HashSet<>(2);
        students.add(student);
        students.add(student2);
        System.out.println(students.size());//不重写hashCode居然是两个，因为放入set！
    }
}

@Data
@Getter
class Student {
    private String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}